package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/channel")
@Api
public class WmChannelController {
    @Autowired
    private IWmChannelService channelService;

    /**
     * 根据名称查询频道列表
     * @param
     * @return
     */
    @PostMapping("/list")
    @ApiOperation(value = "根据名称查询频道")
    public ResponseResult listByName(@RequestBody ChannelDto dto){
        return channelService.listByName(dto);
    }

    /**
     * 查询所有频道
     * @return
     */
    @GetMapping("channels")
    public ResponseResult channels(){
        LambdaQueryWrapper<WmChannel> query = new LambdaQueryWrapper<>();
        query.orderByDesc(WmChannel::getId);
        List<WmChannel> list =channelService.list(query);
        return  ResponseResult.okResult(list);
    }
    /**
     * 新增频道
     * @param channel
     * @return
     */
    @PostMapping
    public ResponseResult<Integer> saveChannel(@RequestBody WmChannel channel){
        return channelService.saveChannel(channel);
    }
}

